package com.mymail.myutil;

import javax.mail.AuthenticationFailedException;

import com.mymail.entity.Mail;
import com.mymail.entity.MailBox;
import com.mymail.entity.Receiver;
import com.mymail.entity.User;

public class Send {
	public static String error="";
	
	/**
	 * 发送邮件的静态方法
	 * @param from
	 * @param to 是一用；连接的收件人组
	 * @param subject
	 * @param content 是html格式 的
	 * @param chaosong 是一用；连接的多个抄送
	 * @param misong 是一用；连接的多个密送
	 * @return
	 * 
	 */
	public static boolean sendMail(String from, String to, String subject,
			String content, String chaosong, String misong,User user) {
		Mail mail=new Mail();
		mail.setFrom(from);
		mail.setSubject(subject);
		mail.setContent(content);
		mail.setFolder(user.findFolder("已发送").getId());
		//mail.setSort(Mail.YIFA);
		Receiver rec=new Receiver();
		rec.setName(to);
		rec.setSort(Receiver.NORMAL);
		mail.addReceiver(rec);
		MailBox box=user.findMailbox(from);
		try {
			box.sendMail(mail);
		} catch (AuthenticationFailedException e) {
			error="邮箱用户名或密码错误！";
			return false;
			//e.printStackTrace();
		}
		return true;
	}

}
